package com.baoteng.captcha.recognition.vo;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;

import com.google.common.collect.Maps;

public class PAEigenvalue {

	private int pixels;
	private int height;
	private int weight;
	private String character;
	private static Map<Integer,List<PAEigenvalue>> eigenvalue = Maps.newHashMap();
	
	static{
		eigenvalue.putIfAbsent(208, Arrays.asList(new PAEigenvalue[]{new PAEigenvalue(208,18,29,"6")}));
		eigenvalue.putIfAbsent(212, Arrays.asList(new PAEigenvalue[]{new PAEigenvalue(212,19,29,"8")}));
		eigenvalue.putIfAbsent(168, Arrays.asList(new PAEigenvalue[]{new PAEigenvalue(168,17,29,"9")}));
		eigenvalue.putIfAbsent(211, Arrays.asList(new PAEigenvalue[]{new PAEigenvalue(211,19,29,"B")}));
		eigenvalue.putIfAbsent(204, Arrays.asList(new PAEigenvalue[]{new PAEigenvalue(204,20,29,"D")}));
		eigenvalue.putIfAbsent(164, Arrays.asList(new PAEigenvalue[]{new PAEigenvalue(164,19,29,"P")}));
		eigenvalue.putIfAbsent(193, Arrays.asList(new PAEigenvalue[]{new PAEigenvalue(193,19,29,"Q")}));
		eigenvalue.putIfAbsent(205, Arrays.asList(new PAEigenvalue[]{new PAEigenvalue(205,18,29,"R")}));
	}
	
	private static class PAEigenvalueHandle {
		
		private static final PAEigenvalue factory = new PAEigenvalue();
			
	}
	
	public static PAEigenvalue newInstance(){
		return PAEigenvalueHandle.factory;
	}
	
	private BiFunction<Integer, Integer, String> getCharOfPixels;
	
	private PAEigenvalue() {
		
	}

	private PAEigenvalue(int pixels, int height, int weight, String character) {
		super();
		this.pixels = pixels;
		this.height = height;
		this.weight = weight;
		this.character = character;
	}
	
	public String getCharOfPixels(Integer pixels,Integer weight,
            Integer height)
	{
		List<PAEigenvalue> _eigenvalue=eigenvalue.get(pixels);
		return _eigenvalue!=null?_eigenvalue.get(0).getCharacter():null;
//		if(pixels==212 && weight!=null && height!=null){
//			List<PAEigenvalue> temp = _eigenvalue.stream().filter(item -> item.getWeight()==weight&& item.getHeight()==height?true:false).collect(Collectors.toList());
//			return temp!=null ? temp.get(0).getCharacter():null;
//		}else{
//			return _eigenvalue!=null?_eigenvalue.get(0).getCharacter():null;
//		}
	}

	public int getPixels() {
		return pixels;
	}

	public void setPixels(int pixels) {
		this.pixels = pixels;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public String getCharacter() {
		return character;
	}

	public void setCharacter(String character) {
		this.character = character;
	}

	public BiFunction<Integer, Integer, String> getGetCharOfPixels() {
		return getCharOfPixels;
	}

	public void setGetCharOfPixels(BiFunction<Integer, Integer, String> getCharOfPixels) {
		this.getCharOfPixels = getCharOfPixels;
	}
	
}
